KISSY.use("node",function(S,Node){ 
var $=Node.all;
var lvT= ["瞎子", "色盲", "色郎", "色狼", "色鬼", "色魔", "超级色魔", "变态色魔", "孤独求色"];
var lvMap= [2, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9];
var lvFinal=2;
var scFinal=0;
var top_sign = $(".sign").val();
function start(lev,stat){
	$(".box").removeClass("lv"+(lvMap[lev]-1));
	$(".box").addClass("lv"+lvMap[lev]);
	var html="<span>";
	var bxs = lvMap[lev]*lvMap[lev];
	var xpint = rnd(0, bxs-1)
	for(var i=0;i<bxs;i++){
		 if(i==xpint){
			html +="<i class=\"p\"></i>";
		 }else{
			html += "<i></i>";
		 }
	}
	html += "</span>";
	if(stat){
	html += '<div class="start" style="width:280px;height: 100px;position: absolute;padding:80px 10px 0 10px;color:#FFF">点击不同颜色，30秒内点的越多分越高<button data-type="color" class="btn play-btn">开始游戏</button></div>';
	}
	$(".box").empty();
	$(html).appendTo(".box");
	var xran = 0;
	if(lvMap[lev]<5){
		 xran = 15;
	}else{
		 xran = 10;
	}
	var color = [rnd(0,255),rnd(0,255),rnd(0,255)];
	var ccode = "rgb("+color[0]+","+color[1]+","+color[2]+")";
	var xcode = "rgb("+(color[0]+xran)+","+(color[1]+xran)+","+(color[2]+xran)+")";
	
	$("i").css("background-color",ccode);
	$(".p").css("background-color",xcode);
	$(".p").on("click",function(){
		$(".box").empty();
		if(lev<lvMap.length-1){
			start(lev+1,false);
		}else{
			start(lev,false);
		}
		lvFinal=lvMap[lev];
		scFinal=lev;
	});
}
start(0,true);

function start_ready(){
	$(".box").removeClass("lv"+lvFinal);
	lvFinal=2;
	$(".play-btn").on("click",function(){
		KISSY.io({
			url: "/?a=tsm_st&m=Shopmodule",
			data:{"top_sign":top_sign},
			success: function(data, textStatus) {
				if(data.status==true){
					game_start();
				}else{
					alert('游戏开始失败！请确认您是在店铺中玩游戏，我们不接待来路不明的客户！');
				}
			},
			error: function(){
				alert('error');
			},
			//发送请求类型是jsonp
			dataType:"jsonp"
		});
	});
}
start_ready();

function game_start(){
$(".start").hide();
	start(0,false);
	var t = 30;
	var ts = setInterval(function(){
		$(".play_time").html("<span>"+(--t)+"</span>秒");
		if(t==0){
			KISSY.io({
				url: "/?a=tsm_ed&m=Shopmodule",
				data:{"score":scFinal,"level":lvFinal,"sid":$(".sid").val()},
				success: function(data, textStatus) {
					$(".scoreid").val(data.score_id);
				},
				error: function(){
					alert('error');
				},
				//发送请求类型是jsonp
				dataType:"jsonp"
			});
			clearInterval(ts);
			var html = '<div class="start">经鉴定，您是：<span style="font-size:36px">'+lvT[(lvFinal-2)]+'</span><button data-type="color" class="btn play-btn">重新开始</button></div>';
			$(".box").empty();
			$(html).appendTo(".box");
			start_ready();
			}
	},1000);
}
function rnd(min, max)
{
	return parseInt((Math.random()*999)%(max-min+1))+min;
}
});